<template>
    <div class="listDiv">
        <div class="searchDiv">
            <DateRange v-model:start="obj.req.starttime" v-model:end="obj.req.endtime" sph="匹配" eph="发布时间" />
            <el-input clearable placeholder="匹配产品名称" v-model="obj.req.key" class="search_key ml5" />
            <span class="btn search" @click="init">搜索</span>
            <span class="btn refresh" @click="obj.req.currentpage=1;init()"></span>
            <!-- <div class="searchRight">
                <span class="btn add" @click="add">添加资讯</span>
            </div> -->
        </div>
        <div class="table_box"><div class="table_" id="tb">
            <ul class="head">
                <li class="mw300">金融产品名称</li>
                <li class="wcen">价格/元</li>
                <li class="">发布机构</li>
                <li class="">联系人</li>
                <li class="wcen">联系电话</li>
                <li class="mw200 wcen">发布时间</li>
                <li class="wcen">审核状态</li>
                <li class="wcen">操作</li>
            </ul>
            <div class="body">
                <ul v-for="x in obj.ary" :key="x">
                    <li class="mw300">
                        <el-tooltip class="box-item" effect="dark" :content="x.name" placement="top-start" :disabled="x.name.length<17">
                            <div class="lineOne pointer">{{x.name}}</div>
                        </el-tooltip>
                    </li>
                    <li class="wcen">{{x.price}}</li>
                    <li class="">{{x.mechanismname}}</li>
                    <li class="">{{x.man}}</li>
                    <li class="wcen">{{x.mobile}}</li>
                    <li class="mw200 wcen">{{x.intime}}</li>
                    <li class="wcen">
                        <div :class="[globalData.verifyTypeAry[x.verify_state].label]">{{globalData.verifyTypeAry[x.verify_state].text}}</div>
                    </li>
                    <li class="wcen">
                        <DelConfirm class="" isclass="edit_btn" buttontype="success" @yesClick="del(x,1)" @noClick="del(x,2)" title="确认要审核通过吗？" text="审核" yes="通过" no="拒绝" />
                    </li>
                </ul>
            </div>
        </div>
        </div><Pager :value="obj.req" :init="init" />
    </div>
</template>

<script setup>
    import { reactive, getCurrentInstance, ref, toRefs, provide, computed } from 'vue'
    import DateRange from '@/components/date_range.vue'
    import Pager from '@/components/pager.vue'
    import DelConfirm from '@/components/del_confirm.vue'
    import { ElMessageBox } from 'element-plus'
    let { proxy } = getCurrentInstance()

    let obj = reactive({
        verifyType:['未审核','已审核'],
        ary: [],
        req: {
            currentpage: 1,
            pagesize: 10,
            count: 0,
            key: "",
            type:"",
            endtime: "",
            starttime: "",
        },
        alltype:[],
    });
    let befortinit = async () => {
        obj.alltype = await proxy.$utils.getFinancialPolicyType(proxy)
    }
    befortinit()
    let init = () => {
        proxy.$ajax({
            url: '/banking/list',
            data: obj.req,
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                obj.ary = d.msg.list
                obj.req.count = d.msg.count
            }
        }).catch(() => { })
    }

    let del = (x,v) => {
        if(v==2){
            ElMessageBox.prompt('拒绝原因', '拒绝', {
                confirmButtonText: '确认',
                cancelButtonText: '取消',
                inputPlaceholder: '请输入审核原因',
                inputErrorMessage: 'Invalid Email',
            }).then(({ value }) => {
                examineverify(x.banking_id,v,value)
            }).catch(() => {})
        }else{
            examineverify(x.banking_id,v)
        }
    }

    const examineverify = (id,v,refuse)=>{
        // return
        proxy.$ajax({
            url: '/banking/verify',
            data: { banking_id: id , verify_state: v,refuse:refuse||''},
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                proxy.elMessageMixin("审核成功", 'success')
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
</script>

<style scoped>
    ::-webkit-scrollbar { width:10px; background-color: #FFFFFF; }
    .search_select { width:100px!important; }
    .search_key { width:160px!important; }
    #tb ul li.li2 { width: 100px; }
    #tb ul li.li3 { width: 45px; }
    #tb ul li.li4 { width: 65px; }
    #tb ul li.li5 { width: 135px; }
</style>